package com.syg.servlet11_Filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.*;
import java.io.IOException;

public class _05_FilterGetInitParam implements Filter {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    public _05_FilterGetInitParam() {
        logger.info("_05_FilterGetInitParam()==>E1,filter无参构造执行了(第五个filter)");
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        logger.info("init()==>E2,filter初始化方法执行了(第五个filter)");
//        String filterName = filterConfig.getFilterName();
//        String username = filterConfig.getInitParameter("username");
//        String password = filterConfig.getInitParameter("password");
//        System.out.println("filter name is"+filterName);
//        System.out.println("get web.xml in param:"+username);
//        System.out.println("get web.xml in param:"+password);
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        logger.info("doFilter()==>E3,filter放行之前(第五个filter)");
        filterChain.doFilter(servletRequest,servletResponse);//让目标资源执行
        logger.info("doFilter()==>E4,filter放行之后(第五个filter)");
    }

    @Override
    public void destroy() {
        logger.info("destroy()==>E5,Filter销毁了(第五个filter)");
    }
}
